package com.xh.xyzp.oss.controller;

import com.xh.xyzp.common.domain.vo.resp.ApiResult;
import com.xh.xyzp.oss.domain.vo.req.FileUploadReq;
import com.xh.xyzp.oss.domain.vo.resp.FileResp;
import com.xh.xyzp.oss.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: xianghao
 * @Description:
 * @Date: 2024-11-12  18:00
 */
@Api(tags = "OSS接口")
@RestController
@RequestMapping("/oss")
public class FileController {

    @Autowired
    private FileService fileService;

//    @ApiPermission(permissions = {PermissionConstant.FILE_UPLOAD})
    @ApiOperation("上传文件")
    @PostMapping("/upload")
    public ApiResult<FileResp> upload(FileUploadReq req){
        return ApiResult.success(fileService.upload(req));
    }


//    @ApiPermission(permissions = {PermissionConstant.FILE_DOWNLOAD})
    @ApiOperation("获取文件")
    @GetMapping("/download/{fileId}")
    public ResponseEntity<byte[]> download(@PathVariable("fileId") Long fileId){
        return fileService.download(fileId);
    }


}
